<script>

function ValidEmail(emstr)
{
var vEMailID=emstr
var atPos= vEMailID.indexOf("@") + 1
var lastDotPos= vEMailID.lastIndexOf(".") + 1
var firstDotPos = vEMailID.indexOf(".") + 1
var atInstances=0
var dotInstances=0
var inValid = new Array()
var errorMessages = new Array()
var errNo = 0
for(var i=0;i<vEMailID.length;i++)
{
	if(vEMailID.charAt(i)=="@" )
	atInstances+=1
	else if(vEMailID.charAt(i)==".")
	dotInstances=1
}

inValid[errNo] = (atInstances==0)
errorMessages[errNo] = "@ symbol is missing"
errNo++

inValid[errNo] = (dotInstances==0)
errorMessages[errNo] = ". symbol is missing"
errNo++

inValid[errNo] = (atInstances>1)
errorMessages[errNo] = "@ symbol should not repeat"
errNo++

inValid[errNo] = (Math.abs(firstDotPos-atPos)==1)
errorMessages[errNo] = "@ and . symbols can't come together"
errNo++

inValid[errNo] = ((lastDotPos-atPos)<=1)
errorMessages[errNo] = ". symbol is missing"
errNo++

inValid[errNo] = (atPos==vEMailID.length)
errorMessages[errNo] = "@ symbol can't appear at end"
errNo++

inValid[errNo] = (lastDotPos==vEMailID.length)
errorMessages[errNo] = ". symbol can't appear at end"
errNo++

inValid[errNo] = (atPos==0)
errorMessages[errNo] = "@ symbol is missing"
errNo++

inValid[errNo] = (atPos==1)
errorMessages[errNo] = "@ symbol should not appear at first position"
errNo++

inValid[errNo] = (firstDotPos==0)
errorMessages[errNo] = ". symbol is missing"
errNo++

inValid[errNo] = (firstDotPos==1)
errorMessages[errNo] = ". symbol should not appear at first position"
errNo++

inValid[errNo] = (vEMailID.indexOf(" ")>=0)
errorMessages[errNo] = "Email can't contain blank spaces."
errNo++

inValid[errNo] = (vEMailID.indexOf("/")>=0) || (vEMailID.indexOf("\\")>=0)
errorMessages[errNo] = "Email can't contain \\ or /"
errNo++

var fullErrorMessage = "Invalid " + name + " email address.\n"
for(var ind=0; ind<errNo; ind++)
{
	if(inValid[ind])
	{
		fullErrorMessage += errorMessages[ind] + "\n"
		alert(fullErrorMessage)			
		return false
	}
}
var SingleQuotePos = vEMailID.indexOf("'") 
if(SingleQuotePos!=-1)
{
	alert("Enter valid characters.Single Quotes ( ' ) are not allowed.")					
	return false;
} 

return true;
}


function phoneNumber(val)
{    valid="1234567890-+";
	 sizechar=val.length;
     for (var i=0; i<sizechar; i++)
	 {
     	if (valid.indexOf(val.charAt(i)) < 0)
		{
        	return false;
       	}
     }
}

function number(val)
{    valid="1234567890-+";
	 sizechar=val.length;
     for (var i=0; i<sizechar; i++)
	 {
     	if (valid.indexOf(val.charAt(i)) < 0)
		{
        	return false;
       	}
     }
}

function validate()
{	
	/*if(document.new_user.first_name.value=="")
	{
		alert("First Name cannot be blank");
		document.new_user.first_name.focus();
		return false;
	}
	
	if(document.new_user.last_name.value=="")
	{
		alert("Last Name cannot be blank");
		document.new_user.last_name.focus();
		return false;
	}
	
	if(document.new_user.login.value=="")
	{
		alert("Login Name cannot be blank");
		document.new_user.login.focus();
		return false;
	}
	
	if(document.new_user.password.value=="")
	{
		alert("Password cannot be blank");
		document.new_user.password.focus();
		return false;
	}
	
	if(document.new_user.user_email.value=="")
	{
		alert("Email cannot be blank");
		document.new_user.user_email.focus();
		return false;
	}
	
	if(document.new_user.user_email.value!="")
	{
		if (ValidEmail(document.new_user.user_email.value)==false)
		{
		//alert("Please enter valid email address");
		return false;
		}
	}
	
	if(document.new_user.zip_code.value=="")
	{
		alert("Zip Code cannot be blank");
		document.new_user.zip_code.focus();
		return false;
	}
	
	if(document.new_user.zip_code.value!="")
	{
		if (number(document.new_user.zip_code.value)==false)
		{
		alert("Please enter valid zip code");
		document.new_user.zip_code.focus();
		return false;
		}
	}
	
	
	
	if(document.new_user.city_id.value=="")
	{
		alert("City cannot be blank");
		document.new_user.city_id.focus();
		return false;
	}
	
	if(document.new_user.state_id.value=="")
	{
		alert("State cannot be blank");
		document.new_user.state_id.focus();
		return false;
	}
	
	*/
	
	
	if (document.new_user.user_dp_lower.value=="")
	{
		alert("Please enter lower price limit");
		document.new_user.user_dp_lower.focus();
		return false;
	}
	
	if(document.new_user.user_dp_lower.value!="")
	{
		if (number(document.new_user.user_dp_lower.value)==false)
		{
		alert("Please enter valid input");
		document.new_user.user_dp_lower.focus();
		return false;
		}
	}
	
	
	if (document.new_user.user_dp_upper.value=="")
	{
		alert("Please enter upper price limit");
		document.new_user.user_dp_upper.focus();
		return false;
	}
	
	if(document.new_user.user_dp_upper.value!="")
	{
		if (number(document.new_user.user_dp_upper.value)==false)
		{
		alert("Please enter valid input");
		document.new_user.user_dp_upper.focus();
		return false;
		}
	}
	

	if (document.new_user.user_dp_upper.value!="" && document.new_user.user_dp_lower.value!="")
	{
		if (document.new_user.user_dp_lower.value > document.new_user.user_dp_upper.value)
		{
			alert("Please enter correct price range");
			document.new_user.user_dp_upper.focus();
			return false;
		}
	}

	
	
	if (document.new_user.security_code.value=="")
	{
		alert("Please enter security code");
		document.new_user.security_code.focus();
		return false;
	}
	
	
	
	

return true;	
}




</script>


<?
if(isset($_REQUEST['Submit']) && $_REQUEST['Submit'] != "")
{
	
	if (($_REQUEST['security_code'] != "")  && ($_SESSION['security_code'] == $_REQUEST['security_code']))
 	{
	
	$created= date("Y-m-d h:i:s");
	$modified= date("Y-m-d h:i:s");
	
	$dob = $_REQUEST['year']."-".$_REQUEST['month']."-".$_REQUEST['day'];
	$user_intrst_cat = "";
	$user_intrst_cat1=$_REQUEST['user_intrst_cat'];
	if ($user_intrst_cat1){
	 foreach ($user_intrst_cat1 as $t)
	 {
		
		$user_intrst_cat  = $user_intrst_cat."".$t."-"; 
	 }
	}
		
	$obj->add_user($created, $modified, $_REQUEST["first_name"],  $_REQUEST["last_name"], $_REQUEST["middle_name"], $_REQUEST["login"], $_REQUEST["password"], $_REQUEST["gender_id"], $dob, $_REQUEST["about_me"], $_REQUEST["address"], $_REQUEST["city_id"], $_REQUEST["state_id"], $_REQUEST["country_id"], $_REQUEST["zip_code"], $_REQUEST["user_email"], $_REQUEST["user_mobile"], $_REQUEST["user_phone"], $user_intrst_cat, $_REQUEST["user_dp_lower"], $_REQUEST["user_dp_upper"], $_REQUEST["user_status"], $conn );
	
	
	}
	else
	{
		
		 $error = 1;
	
	}

}

?>
<style type="text/css">
<!--
.style1 {color: #FF0000}
-->
</style>


<form action="" method="post" id="new_user" name="new_user" enctype="multipart/form-data" onSubmit="return validate();">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td height="29" colspan="3"><h3>New User Profile</h3></td>
  </tr>
  
   <? if($error == 1)
	  { ?>
	  
	   <tr>
        <td colspan='3'><div align="center"><span class="style1">You have provided an invalid security code</span></div></td>
	</tr>
<? } ?>
				  
				  
				  
  <tr>
    <td width="7%">&nbsp;</td>
    <td width="15%">First Name *: </td>
    <td width="78%"><input name="first_name" type="text" id="first_name" size="45" /></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>Middle Name: </td>
    <td><input name="middle_name" type="text" id="middle_name" size="45" /></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>Last Name *: </td>
    <td><input name="last_name" type="text" id="last_name" size="45" /></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>Login *:</td>
    <td><input name="login" type="text" id="login" size="45" /></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>Password *:</td>
    <td><input name="password" type="password" id="password" size="45" /></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>Gender:</td>
    <td>
	<select id="gender_id" name="gender_id">
	<option value="1">Male</option>
	<option value="2">Female</option>
	</select>
	</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>Date of Birth: </td>
    <td>
	<select id="month" name="month">
	<option value="1">January</option>
	<option value="2">February</option>
	<option value="3">March</option>
	<option value="4">April</option>
	<option value="5">May</option>
	<option value="6">June</option>
	<option value="7">July</option>
	<option value="8">August</option>
	<option value="9">Spetember</option>
	<option value="10">October</option>
	<option value="11">November</option>
	<option value="12">December</option>
	</select> 
	
	<select id="day" name="day">
	
	<option value="01">01</option>
	<option value="02">02</option>
	<option value="03">03</option>
	<option value="04">04</option>
	<option value="05">05</option>
	<option value="06">06</option>
	<option value="07">07</option>
	<option value="08">08</option>
	<option value="09">09</option>
	<option value="10">10</option>
	<?
	for ($i = 11; $i <= 31; $i++) {
	?>
    <option value="<?=$i?>"><?=$i?></option>
	
	<? }
	?>
	</select>
	
	<select name="year" id="year">
	
	<?
	for ($i = 1940; $i <= 2000; $i++) {
	?>
    <option value="<?=$i?>"><?=$i?></option>
	
	<? }
	?>
	</select>
	
	</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td valign="top">A little About you: </td>
    <td>
	<textarea name="about_me" id="about_me" cols="35" rows="12"></textarea>
	</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>Email *:</td>
    <td><input name="user_email" type="text" id="user_email" size="45" /></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>Phone #:</td>
    <td><input name="user_phone" type="text" id="user_phone" size="45" /></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>Moble #:</td>
    <td><input name="user_mobile" type="text" id="user_mobile" size="45" /></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>Street Adress :</td>
    <td><input name="address" type="text" id="address" size="45" /></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>Zip Code *: </td>
    <td><input name="zip_code" type="text" id="zip_code" size="45" /></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>City *:</td>
    <td><input name="city_id" type="text" id="city_id" size="45" /></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>State *: </td>
    <td><input name="state_id" type="text" id="state_id" size="45" /></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>Country :</td>
    <td>
	<select id="country_id" name="country_id" style="width:310px;">
	
	<?
		$sc = "select * from countries";
		$qc = mysql_query($sc) or die($sc);
		while($rqc = mysql_fetch_array($qc))
			{?>
			<option value="<?=$rqc["id"]?>"><?=$rqc["name"]?></option>
			<? }
		?>
	
	</select>
	</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>Categories of interest *:</td>
    <td valign="bottom">
	<select name="user_intrst_cat[]" id="user_intrst_cat" multiple="multiple" style="width:315px">
	<?
		$sc = "select * from categories where cat_status = '1'";
		$qc = mysql_query($sc) or die($sc);
		while($rqc = mysql_fetch_array($qc))
			{?>
			<option value="<?=$rqc["cat_id"]?>"><?=$rqc["cat_name"]?></option>
			<? }
		?>
		
	
	</select>&nbsp;(hold down ctrl key for multiple selection)	</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>Price Range *: </td>
    <td> <input name="user_dp_lower" type="text" id="user_dp_lower" size="10" maxlength="10" /> 
    &nbsp;to&nbsp;<input name="user_dp_upper" type="text" id="user_dp_upper" size="10" maxlength="10" /> 
    (SEK)  </td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td><img src="CaptchaSecurityImages.php?width=100&height=40&characters=5" /></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>Security Code *:</td>
    <td><input id="security_code" size="45" name="security_code" type="text" class="inputtext" /></td>
  </tr>
  <tr>
    <td colspan="2">&nbsp;</td>
    <td><input type="submit" value="Submit" class="button" name="Submit">&nbsp;<input type="reset" value="Reset" class="button" name="Submit2"></td>
  </tr>
</table>
</form>